import { getDemandLists, getDemandDetails, takeOverDemandInfo, getExportDemandLists } from '../../fetch/modules/demand'

const state = {
    demandLists: {},
    detailInfo:{},
    takeDemandInfo: {},
    exportDemands: {}
}

const actions = {
    GET_DEMAND_LISTS: ({ commit, state }, opts) => {
        return getDemandLists(opts).then(demand => commit('FETCH_DEMAND_LISTS', { demand }))
    },
    GET_DEMAND_DETAIL: ({ commit, state }, opts) => {
        return getDemandDetails(opts).then(demand => commit('FETCH_DEMAND_DETAIL_INFO', { demand }))
    },
    TAKE_OVER_DEMAND: ({ commit, state }, opts) => {
        return takeOverDemandInfo(opts).then(demand => commit('TAKE_OVER_DEMAND_IFNO', { demand }))
    },
    GET_EXPORT_LISTS: ({ commit, state }, opts) => {
        return getExportDemandLists(opts).then(demand => commit('FETCH_EXPORT_LISTS', { demand }))
    }
}
const mutations = {
    FETCH_DEMAND_LISTS: (state, { demand }) => {
        state.demandLists = demand.data;
    },
    FETCH_DEMAND_DETAIL_INFO: (state, { demand }) => {
        state.detailInfo = demand.data;
    },
    TAKE_OVER_DEMAND_IFNO: (state, { demand }) => {
        state.takeDemandInfo = demand.data;
    },
    FETCH_EXPORT_LISTS: (state, { demand }) => {
        state.exportDemands = demand.data;
    }

}

const getters = {
    getDemandLists (state) {
        return state.demandLists
    },
    getDemandDetail(state){
        return state.detailInfo;
    },
    getTakeDemandedInfo(state){
        return state.takeDemandInfo;
    },
    getExportDemandLists(state){
        return state.exportDemands;
    }
}

export default {
    state,
    actions,
    mutations,
    getters
}